package com.wushi.lenovo.asia5b.app_ui.shopcar.adapter;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mvp.images.WImageLoader;
import com.mvp.utils.ResString;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_model.good.bean.PriceDetailType;
import com.wushi.lenovo.asia5b.app_model.good.goodbean.GoodsModel;
import com.wushi.lenovo.asia5b.app_ui.h5.GoodsDetailsActivity;
import com.wushi.lenovo.asia5b.app_ui.orderdetail.PriceDetailActivity;
import com.wushi.lenovo.asia5b.app_widget.mingan.MinganImageView;

import java.util.List;

/**
 * Created by zhangyuncai on 2020/3/2.
 */
public class OrderCheckPiGoodsAdapter extends BaseQuickAdapter<GoodsModel, BaseViewHolder> {

    final boolean isDaigouGoods;

    public OrderCheckPiGoodsAdapter(@Nullable List<GoodsModel> data, boolean isDaigouGoods) {
        super(R.layout.item_ordercheckpi_goodsadapter, data);
        this.isDaigouGoods = isDaigouGoods;
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsModel item) {
        //商品信息
        setGoodView(helper, item);

        //价格详细
        helper.getView(R.id.view_goods_pricedetail).setOnClickListener(v -> {
            PriceDetailActivity.startPriceDetailActivity(mContext, item, isDaigouGoods ? PriceDetailType.ordercheckdaigou : PriceDetailType.ordercheckpi);
        });
        //商品详细
        helper.getView(R.id.mingan_goods).setOnClickListener(v -> {
            GoodsDetailsActivity.startGoodsDetailsActivity(mContext, item.getProduct_id());
        });
    }


    /**
     * 设置商品信息
     *
     * @param helper
     * @param item   商品数据
     */
    private void setGoodView(BaseViewHolder helper, GoodsModel item) {
        //商品名
        TextView tv_goods_goodname = helper.getView(R.id.tv_goods_goodname);
        tv_goods_goodname.setText(item.getName());
        tv_goods_goodname.setOnClickListener(v -> {
            GoodsDetailsActivity.startGoodsDetailsActivity(mContext, item.getProduct_id());
        });

        //商品图片
        MinganImageView mingan_goods = helper.getView(R.id.mingan_goods);
        WImageLoader.displayImage(mContext, item.getImage(), mingan_goods.getImageView());

        //商品属性
        TextView tv_goods_attr = helper.getView(R.id.tv_goods_attr);
        tv_goods_attr.setText(item.getAttr_name());

        //备注
        TextView tv_goods_remark = helper.getView(R.id.tv_goods_remark);
        tv_goods_remark.setText(item.getRemark());

        //价格
        TextView tv_goods_price = helper.getView(R.id.tv_goods_price);
        tv_goods_price.setText(String.format(ResString.get(R.string.price_nun), item.getPrice(), item.getQuantity()));

    }
}
